<!DOCTYPE html>
<!--[if IE 9]>         <html class="no-js lt-ie10" lang="en"> <![endif]-->
<!--[if gt IE 9]><!-->
<html class="no-js" lang="en">
	<!--<![endif]-->

	<head>
		<meta charset="utf-8">

		<title>AppUI - Web App Bootstrap Admin Template</title>

		<meta name="description" content="AppUI is a Web App Bootstrap Admin Template created by pixelcave and published on Themeforest">
		<meta name="author" content="pixelcave">
		<meta name="robots" content="noindex, nofollow">

		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">

		<!-- Icons -->
		<!-- The following icons can be replaced with your own, they are used by desktop and mobile browsers -->
		<link rel="shortcut icon" href="img/favicon.png">
		<link rel="apple-touch-icon" href="img/icon57.png" sizes="57x57">
		<link rel="apple-touch-icon" href="img/icon72.png" sizes="72x72">
		<link rel="apple-touch-icon" href="img/icon76.png" sizes="76x76">
		<link rel="apple-touch-icon" href="img/icon114.png" sizes="114x114">
		<link rel="apple-touch-icon" href="img/icon120.png" sizes="120x120">
		<link rel="apple-touch-icon" href="img/icon144.png" sizes="144x144">
		<link rel="apple-touch-icon" href="img/icon152.png" sizes="152x152">
		<link rel="apple-touch-icon" href="img/icon180.png" sizes="180x180">
		<!-- END Icons -->

		<!-- Stylesheets -->
		<!-- Bootstrap is included in its original form, unaltered -->
		<link rel="stylesheet" href="css/bootstrap.min.css">

		<!-- Related styles of various icon packs and plugins -->
		<link rel="stylesheet" href="css/plugins.css">

		<!-- The main stylesheet of this template. All Bootstrap overwrites are defined in here -->
		<link rel="stylesheet" href="css/main.css">

		<!-- Include a specific file here from css/themes/ folder to alter the default theme of the template -->

		<!-- The themes stylesheet of this template (for using specific theme color in individual elements - must included last) -->
		<link rel="stylesheet" href="css/themes/amethyst.css">
		<!-- END Stylesheets -->

		<!-- Modernizr (browser feature detection library) -->
		<script src="js/vendor/modernizr-3.3.1.min.js"></script>
	</head>

	<body>
		<!-- Page Wrapper -->
		<!-- In the PHP version you can set the following options from inc/config file -->
		<!--
            Available classes:

            'page-loading'      enables page preloader
        -->
		<div id="page-wrapper" class="page-loading">
			<!-- Preloader -->
			<!-- Preloader functionality (initialized in js/app.js) - pageLoading() -->
			<!-- Used only if page preloader enabled from inc/config (PHP version) or the class 'page-loading' is added in #page-wrapper element (HTML version) -->
			<div class="preloader">
				<div class="inner">
					<!-- Animation spinner for all modern browsers -->
					<div class="preloader-spinner themed-background hidden-lt-ie10"></div>

					<!-- Text for IE9 -->
					<h3 class="text-primary visible-lt-ie10"><strong>Loading..</strong></h3>
				</div>
			</div>
			<!-- END Preloader -->

			<!-- Page Container -->
			<!-- In the PHP version you can set the following options from inc/config file -->
			<!--
                Available #page-container classes:

                'sidebar-light'                                 for a light main sidebar (You can add it along with any other class)

                'sidebar-visible-lg-mini'                       main sidebar condensed - Mini Navigation (> 991px)
                'sidebar-visible-lg-full'                       main sidebar full - Full Navigation (> 991px)

                'sidebar-alt-visible-lg'                        alternative sidebar visible by default (> 991px) (You can add it along with any other class)

                'header-fixed-top'                              has to be added only if the class 'navbar-fixed-top' was added on header.navbar
                'header-fixed-bottom'                           has to be added only if the class 'navbar-fixed-bottom' was added on header.navbar

                'fixed-width'                                   for a fixed width layout (can only be used with a static header/main sidebar layout)

                'enable-cookies'                                enables cookies for remembering active color theme when changed from the sidebar links (You can add it along with any other class)
            -->
			<div id="page-container" class="header-fixed-top">
				<!-- Main Container -->
				<div id="main-container">
					<!-- Header -->
					<!-- In the PHP version you can set the following options from inc/config file -->
					<!--
                        Available header.navbar classes:

                        'navbar-default'            for the default light header
                        'navbar-inverse'            for an alternative dark header

                        'navbar-fixed-top'          for a top fixed header (fixed main sidebar with scroll will be auto initialized, functionality can be found in js/app.js - handleSidebar())
                            'header-fixed-top'      has to be added on #page-container only if the class 'navbar-fixed-top' was added

                        'navbar-fixed-bottom'       for a bottom fixed header (fixed main sidebar with scroll will be auto initialized, functionality can be found in js/app.js - handleSidebar()))
                            'header-fixed-bottom'   has to be added on #page-container only if the class 'navbar-fixed-bottom' was added
                    -->
					<header class="navbar navbar-inverse navbar-fixed-top">
						<!-- Left Header Navigation -->
						<ul class="nav navbar-nav-custom">
							<!-- Header Link -->
							<li class="hidden-xs animation-fadeInQuick">
								<a href="survey.html"><strong><big>问道</big></strong></a>
							</li>
							<!-- END Header Link -->
						</ul>
						<!-- END Left Header Navigation -->

						<!-- Right Header Navigation -->
						<ul class="nav navbar-nav-custom pull-right">
							<!-- User Dropdown -->
							<li class="dropdown">
								<span> </span>
								<a  onclick="logout()" class="dropdown-toggle" data-toggle="dropdown">
									注销
								</a>
							</li>
								<!-- END User Dropdown -->
						</ul>
						<!-- END Right Header Navigation -->
					</header>
					<!-- END Header -->

					<!-- Page content -->
					<div id="page-content">
						<!-- Blank Header -->
						<div class="content-header">
							<div class="row">
								<div class="col-sm-12">
									<div class="header-section" style="width: 100%;">
										<h1 class="inline">调查详情</h1>
										<h5 class="inline">-<a href="#modal-chgTitle" data-toggle="modal" id="survey-name"></a></h5>
										<span class="label label-success" style="margin-left: 40px;" id="survey-state">已提交</span>
										<h5 class="inline" style="margin-left: 20px;" id="survey-period">周期：2018.09.18~2018.10.18</h3>
										<span class="pull-right">
											 <span id="btn-outer">
												
											</span>
											<a class="btn btn-danger" data-toggle = "modal" href="#modal-delete">删除</a>
										</span>
									</div>
								</div>
							</div>
						</div>
						<!-- END Blank Header -->

						<div class="row">
							<div class="col-sm-10 col-sm-offset-1 col-md-10 col-md-offset-1 col-lg-10 col-lg-offset-1">
								<div class="block full">
									<div class="block-title">
										<h2>调查链接</h2>
										 
									</div>
									<p class="well text-center">
										<a id="survey-url"></a>
										<span class="text-center" style="float: right;padding: 0;margin-top: -.5%;margin-right: 1.6%;">
											<button class="btn btn-primary" type="button" onClick="copyUrl()" id="survey-copy" >复制</button>
										</span>
									</p>
								</div>
								<div class="block full">
									<div class="block-title">
										<h2>绑定</h2>
									</div>
									<div class="block full">
										<form action="" class="form-horizontal" style="width: 100%;">
											<div class="form-group">
												<div class="col-md-10" style="width: 100%;">
													<p class="well text-center" style="width: 100%;">
														<a id="survey-title" style="display: inline;"></a>
														<span class="text-center" style="float: right;padding: 0;margin-top: -.5%;">
															<button class="btn btn-primary" type="button" onclick="preview(this.name)" id="survey-preview" >预览</button>
														</span>
													</p>
												</div>
											</div>
										</form>
									</div>
								</div>
							</div>
						</div>
						<!-- chgTitle Modal -->
						<div id="modal-chgTitle" class="modal" tabindex="-1" role="dialog" aria-hidden="true">
							<div class="modal-dialog">
								<div class="modal-content">
									<div class="modal-header">
										<!--<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>-->
										<h3 class="modal-title"><strong>请输入新的问卷名称</strong></h3>
										 
									</div>
									<div class="modal-body">
										<!--<h4>请输入新的问卷名称</h3>-->
										<input type="text" name="newTitle" id="newTitle" value="" class="form-control"/>
										<div id='quesnote' style='margin-left:1%;margin-top:2%;color:red'></div>
									</div>
									<div class="modal-footer">
										<button type="button" onclick="submit()" class="btn btn-effect-ripple btn-primary">确定</button>
										<button type="button" class="btn btn-effect-ripple btn-danger" data-dismiss="modal">取消</button>
									</div>
								</div>
							</div>
						</div>
						<!-- END chgTitle Modal -->
						<!-- delete Modal -->
								<div id="modal-delete" class="modal" tabindex="-1" role="dialog" aria-hidden="true">
									<div class="modal-dialog">
										<div class="modal-content">
											<div class="modal-header">
												<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
												<h3 class="modal-title"><strong>提示</strong></h3>
											</div>
											<div class="modal-body">
												是否删除该调查？
											</div>
											<div class="modal-footer">
												<button type="button" class="btn btn-effect-ripple btn-primary" onclick="deleteSurvey()">确定</button>
												<button type="button" class="btn btn-effect-ripple btn-danger" data-dismiss="modal">取消</button>
											</div>
										</div>
									</div>
								</div>
								<!-- END delete Modal -->
								<!-- notStart Modal -->
								<div id="modal-notStart" class="modal" tabindex="-1" role="dialog" aria-hidden="true">
									<div class="modal-dialog">
										<div class="modal-content">
											<div class="modal-header">
												<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
												<h3 class="modal-title"><strong>提示</strong></h3>
											</div>
											<div class="modal-body">
												该调查处在未开始状态，是否更改调查周期，运行此调查？
												<div class="row">
													<div class="col-md-12">
														<div class="block full">
															<div class="input-group input-daterange" data-date-format="yyyy-mm-dd">
																<input type="text" id="notStart-startTime" name="startTime" class="form-control" placeholder="起始日期">
																<span class="input-group-addon">至</span>
																<input type="text" id="notStart-endTime" name="endTime" class="form-control" placeholder="终止日期">
															</div>
														</div>
													</div>
												</div>
											</div>
											<div class="modal-footer">
												<button type="button" class="btn btn-effect-ripple btn-primary" onclick="chgState1()">确定</button>
												<button type="button" class="btn btn-effect-ripple btn-danger" data-dismiss="modal">取消</button>
											</div>
										</div>
									</div>
								</div>
								<!-- ENDStart Modal -->
								 <div id="modal-ended" class="modal" tabindex="-1" role="dialog" aria-hidden="true">
									<div class="modal-dialog">
										<div class="modal-content">
											<div class="modal-header">
												<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
												<h3 class="modal-title"><strong>提示</strong></h3>
											</div>
											<div class="modal-body">
												该调查处在已结束状态，是否更改调查周期，运行此调查？
												<div class="row">
													<div class="col-md-12">
														<div class="block full">
															<div class="input-group input-daterange" data-date-format="yyyy-mm-dd">
																<input type="text" id="ended-startTime" name="startTime" class="form-control" placeholder="起始日期">
																<span class="input-group-addon">至</span>
																<input type="text" id="ended-endTime" name="endTime" class="form-control" placeholder="终止日期">
															</div>
														</div>
													</div>
												</div>
											</div>
											<div class="modal-footer">
												<button type="button" class="btn btn-effect-ripple btn-primary" onclick="chgState2()">确定</button>
												<button type="button" class="btn btn-effect-ripple btn-danger" data-dismiss="modal">取消</button>
											</div>
										</div>
									</div>
								</div>
								<!-- END ended Modal -->
								 
					</div>
					<!-- END Page Content -->
				</div>
				<!-- END Main Container -->
			</div>
			<!-- END Page Container -->
		</div>
		<!-- END Page Wrapper -->

		<!-- jQuery, Bootstrap, jQuery plugins and Custom JS code -->
		<script src="js/vendor/jquery-2.2.4.min.js"></script>
		<script src="js/vendor/bootstrap.min.js"></script>
		<script src="js/plugins.js"></script>
		<script src="js/app.js"></script>

		<!-- Load and execute javascript code used only in this page -->
		<script src="js/pages/uiTables.js"></script>
		<script>
			var ip='http://10.11.125.124:80/questionnaire',
				getUrl='/survey/detail';
				getqUrl = '/detail'
			var id = '';
			//表格数据集合
			var dataSet = [];
			
			$(function() {
				UiTables.init();
				
				getID();
				getDetail();
			});
			
			function logout(){
				$.ajax({
					type:"get",
					url:ip+"/logout",
					data:{},
					async:true,
					dataType: "json",
					xhrFields: {withCredentials: true},
      				crossDomain:true,
      				success:function(res)
      				{
      					 if(!res.code){
      					 	window.location.href="login.html"
      					 }
      				}
				});	
			}
			
			function getID() {
				url = location.search;
				if(url.indexOf("?") != -1) { //判断是否有参数
					var str = url.substr(1); //从第一个字符开始 因为第0个是?号 获取所有除问号的所有符串
					strs = str.split("="); //用等号进行分隔 （因为知道只有一个参数 所以直接用等号进分隔 如果有多个参数 要用&号分隔 再用等号进行分隔）
					console.log(strs[1]); //直接弹出第一个参数 （如果有多个参数 还要进行循环的）
					id = strs[1];
				}
			}
			
			function getDetail() {
				$.ajax({
					type: "get",
					url: ip + getUrl,
					data: {
						id: id
					},
					dataType: "json",
					contentType: "application/json",
					xhrFields: {
						withCredentials: true
					},
					crossDomain: true,
					success: function(res) {
						console.log(res);
						getquestion(res.data);
						setData(res.data);
						$("#survey-url").html(res.data.url);
						 
					},
					async: true
				});
			}
			function copyUrl(){
				//var urld = $("#survey-url").val;
 				 var Url2=document.getElementById("survey-url").innerText;
        var oInput = document.createElement('input');
        oInput.value = Url2;
        document.body.appendChild(oInput);
        oInput.select(); // 选择对象
        document.execCommand("Copy"); // 执行浏览器复制命令
        oInput.className = 'oInput';
        oInput.style.display='none';
        alert('复制成功');
 
			}
			
			
			function getquestion(date){
				$.ajax({
					type: "get",
					url: ip + getqUrl,
					data: {
						id: date.questionsID
					},
					dataType: "json",
					//contentType: "application/json",
					xhrFields: {
						withCredentials: true
					},
					crossDomain: true,
					success: function(res) {
						console.log(res);
						$("#survey-title").html(res.data[0]);
						$("#survey-title").attr("href","checkQuestionnaire.html?id="+date.questionsID)
					},
					async: true
				});
			}
			function setData(data) {
				$("#survey-name").html(data.title);
				$("#survey-title").html(data.title);
				$("#survey-url").html(data.url);
				var status='';
				if(data.state == "running") {
					status = "运行中";
					chgbtn = '<button class="btn btn-warning" style="width: 80px;" onclick="chgState()">暂停</button>';
				} else if(data.state == "paused") {
					status = "暂停中";
					chgbtn = '<button class="btn btn-success" style="width: 80px;" onclick="chgState()">运行</button>';
				} else if(data.state == "notStarted") {
					status = "未开始";
					chgbtn = '<a href="#modal-notStart" data-toggle="modal" class="btn btn-success" style="width: 80px;" >运行</a>';
				} else if(data.state == "ended") {
					status = "已结束";
					chgbtn = '<a href="#modal-ended" data-toggle="modal" class="btn btn-success" style="width: 80px;" >运行</a>';
				}
				$("#survey-state").html(status);
				$("#btn-outer").html(chgbtn);
				
				var period="周期："+data.startTime+"~"+data.endTime;
				$("#survey-period").html(period);
			}
			
			function preview(quesId) {
				var url='checkQuestionnaire.html?id='+quesId;
				window.open(url, '_blank');
			}
			
			function submit() {
				if(!$("#newTitle").val()){
					 	$("#quesnote").html("*输入名称不能为空")
				}else{
				$.ajax({
					type: "put",
					url: ip+"/survey/rename",
					data: {
						id: id,
						title: $("#newTitle").val()
					},
					dataType: "json",
//					contentType: "application/json",
					xhrFields: {
						withCredentials: true
					},
					crossDomain: true,
					success: function(res) {
						console.log(res);
						if((!res.code)&&typeof res.data=="string")
						{
							$("#quesnote").html(res.data);
							
						}else{
							$("#survey-name").html($("#newTitle").val())
							$("#modal-chgTitle").click()
						}
					},
					async: true
				});
				}
			}
			
			var deleteUrl = '/survey/delete';
			
			function deleteSurvey() {
				deleteUrl = deleteUrl + "?id=" + id;

				$.ajax({
					type: "delete",
					url: ip + deleteUrl,
					//					data: {
					//						id: deleteId
					//					},
					dataType: "json",
					//					contentType: "application/json",
					xhrFields: {
						withCredentials: true
					},
					crossDomain: true,
					success: function(res) {
						console.log(res);
						if(res.code == 0) {
							window.close();
						}
					},
					async: true
				});
			}
			//===============================修改状态
						var chgStateUrl='/survey/changeStates';
			
			//未开始
			function chgState1() {
				//				console.log(id);
				$.ajax({
					type: "put",
					url: ip + chgStateUrl,
					data: {
						id: chgId,
						startTime: $("#notStart-startTime").val(),
						endTime: $("#notStart-endTime").val()
					},
					dataType: "json",
					//					contentType: "application/json",
					xhrFields: {
						withCredentials: true
					},
					crossDomain: true,
					success: function(res) {
						console.log(res);
						if(res.code == 0) {
							//先更改周期再更改状态
							chgState();
						}
						//						window.location.href="importMember.html";
						//						window.event.returnValue=false;
					},
					async: true
				});
			}

			//已结束
			function chgState2() {
				//				console.log(id);
				$.ajax({
					type: "put",
					url: ip + chgStateUrl,
					data: {
						id: chgId,
						startTime: $("#ended-startTime").val(),
						endTime: $("#ended-endTime").val()
					},
					dataType: "json",
					//					contentType: "application/json",
					xhrFields: {
						withCredentials: true
					},
					crossDomain: true,
					success: function(res) {
						console.log(res);
						if(res.code == 0) {
							//先更改周期再更改状态
							chgState();
						}
						//						window.location.href="importMember.html";
						//						window.event.returnValue=false;
					},
					async: true
				});
			}

			function chgState() {
				console.log(id);
				$.ajax({
					type: "put",
					url: ip + chgStateUrl,
					data: {
						id: id
					},
					dataType: "json",
					//					contentType: "application/json",
					xhrFields: {
						withCredentials: true
					},
					crossDomain: true,
					success: function(res) {
						console.log(res);
						location.reload();
					},
					async: true
				});
			}
			
			
		</script>

	</body>

</html>